/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Bean.CekStokBarangCabang;
import Bean.CekStokBarangPusat;
import Bean.Pemesanan;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(urlPatterns = {"/DetailPemesanan"})
public class DetailPemesanan extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String kode = request.getParameter("pesanan");
        Pemesanan psn = new Pemesanan();
        CekStokBarangCabang cab = new CekStokBarangCabang();
        CekStokBarangPusat cap = new CekStokBarangPusat();


        ResultSet res = null;
        try {
            res = psn.tampilPemesananKonfirm(kode);
        } catch (SQLException ex) {
            Logger.getLogger(DetailPemesanan.class.getName()).log(Level.SEVERE, null, ex);
        }
        String nama_cab = null;
        try {
            nama_cab = cab.tampilNamaCabang(kode.substring(0, 3));
        } catch (SQLException ex) {
            Logger.getLogger(DetailPemesanan.class.getName()).log(Level.SEVERE, null, ex);
        }
        String id_cab = null, jmlh = null, kode_brg = null, kode_pesan = null;
        String nama_brg = null, stok = null, kode_kate = null;
        try {
            while (res.next()) {
                id_cab = res.getString("ID_CABANG");
                jmlh = res.getString("JUMLAHBARANG");
                kode_brg = res.getString("KODEBARANG");
                kode_pesan = res.getString("KODEPEMESANAN");
            }
        } catch (SQLException ex) {
            Logger.getLogger(DetailPemesanan.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet res1 = cap.tampilStokPusatKonfirm(kode_brg);
        try {
            while (res1.next()) {
                nama_brg = res1.getString("NAMABARANG");
                stok = res1.getString("JUMLAHBARANG");
                kode_kate = res1.getString("KODEKATEGORI");
            }
        } catch (SQLException ex) {
            Logger.getLogger(DetailPemesanan.class.getName()).log(Level.SEVERE, null, ex);
        }



        out.println("<html>");
        out.println("<head>");
        out.println("<title>Status Tambah Stok Pusat Frogstone</title>");
        out.println("<link href=\"css/style_web.css\" rel=\"stylesheet\" type=\"text/css\"/>");
        out.println("</head>");
        out.println("<body id=\"home\">");
        out.println("<div id=\"wrapper\">");
        out.println("<div id=\"header\">");
        out.println("<div id=\"site_title\">");
        out.println("<a href=\"#\"></a>");
        out.println("</div>");
        out.println("<div id=\"header_kanan\">");
        out.println("</div>");
        out.println("<div id=\"content\">");
        out.println("<center>");
        out.println("<h2><b><font color=\"black\" face=\"Verdana\">DETAIL PESANAN</font></b></h2></br>");
        out.println("<table><form action=\"KonfirmasiTerima\">");

        out.println("<tr>");
        out.println("<td><h3>ID Cabang</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + id_cab + "</h3><input type=\"hidden\" name=\"id_cab\" value='" + id_cab + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Nama Cabang</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + nama_cab + "</h3><input type=\"hidden\" name=\"kode_kate\" value='" + kode_kate + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Kode Pemesanan</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + kode_pesan + "</h3><input type=\"hidden\" name=\"kode_pesan\" value='" + kode_pesan + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Kode Barang</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + kode_brg + "</h3><input type=\"hidden\" name=\"kode_brg\" value='" + kode_brg + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Nama Barang</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + nama_brg + "</h3><input type=\"hidden\" name=\"nama_brg\" value='" + nama_brg + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Jumlah Pesan</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + jmlh + "</h3><input type=\"hidden\" name=\"jmlh\" value='" + jmlh + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><h3>Jumlah Stok Tersedia</h3></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><h3>" + stok + "</h3><input type=\"hidden\" name=\"stok\" value='" + stok + "'/></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><input type=\"submit\" name=\"terima\" value=\"TERIMA\"/></form></td>");
        out.println("<td width=\"5\"></td>");
        out.println("<td><form action=\"Admin/KonfirmasiPemesanan.jsp\"><input type=\"submit\" name=\"tolak\" value=\"TOLAK\"/></form></td>");
        out.println("</tr>");

        out.println("</table>");
        out.println("</center>");
        out.println("</div>");
        out.println("</div>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
